<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :span="8">
          <a-form-item label="分类类型" field="classification_type">
            <sa-select v-model="searchForm.classification_type" dict="classification" placeholder="请选择分类类型" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="中文分类名称" field="classification_name_zh">
            <a-input v-model="searchForm.classification_name_zh" placeholder="请输入中文分类名称" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="英文分类名称" field="classification_name_en">
            <a-input v-model="searchForm.classification_name_en" placeholder="请输入英文分类名称" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="日文分类名称" field="classification_name_ja">
            <a-input v-model="searchForm.classification_name_ja" placeholder="请输入日文分类名称" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="韩文分类名称" field="classification_name_ko">
            <a-input v-model="searchForm.classification_name_ko" placeholder="请输入韩文分类名称" />
          </a-form-item>
        </a-col>
      </template>

      <!-- Table 自定义渲染 -->
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import api from '../api/dictionary'

// 引用定义
const crudRef = ref()
const editRef = ref()

// 搜索表单
const searchForm = ref({
  classification_type: '',
  classification_name_zh: '',
  classification_name_en: '',
  classification_name_ja: '',
  classification_name_ko: '',
})


// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  pk: 'dictionary_id',
  recycleApi: api.getRecyclePageList,
  rowSelection: { showCheckedAll: true },
  add: {
    show: true,
    auth: ['/cassification/ClassificationDictionary/save'],
    func: async () => {
      editRef.value?.open()
    },
  },
  edit: {
    show: true,
    auth: ['/cassification/ClassificationDictionary/update'],
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
  delete: {
    show: true,
    auth: ['/cassification/ClassificationDictionary/destroy'],
    func: async (params) => {
      const resp = await api.delete(params)
      if (resp.code === 200) {
        Message.success(`删除成功！`)
        crudRef.value?.refresh()
      }
    },
    realAuth: ['/cassification/ClassificationDictionary/realDestroy'],
    realFunc: async (params) => {
      const resp = await api.realDestroy(params)
      if (resp.code === 200) {
        Message.success(`销毁成功！`)
        crudRef.value?.refresh()
      }
    },
  },
  recovery: {
    show: true,
    auth: ['/cassification/ClassificationDictionary/recovery'],
    func: async (params) => {
      const resp = await api.recovery(params)
      if (resp.code === 200) {
        Message.success(`恢复成功！`)
        crudRef.value?.refresh()
      }
    },
  },
})

// SaTable 列配置
const columns = reactive([
  { title: '分类类型', dataIndex: 'classification_type', dict: 'classification', width: 120 },
  { title: '中文分类名称', dataIndex: 'classification_name_zh', width: 180 },
  // { title: '英文分类名称', dataIndex: 'classification_name_en', width: 180 },
  // { title: '日文分类名称', dataIndex: 'classification_name_ja', width: 180 },
  // { title: '韩文分类名称', dataIndex: 'classification_name_ko', width: 180 },
  { title: '排序', dataIndex: 'sort_order', width: 180 },
])

// 页面数据初始化
const initPage = async () => {}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
<style>
.arco-tag.arco-tag-custom-color {
    color: initial; /* 使用默认颜色 */
    /* 或者设置成其他颜色，例如：
    color: #333; 
    */
}
</style>